﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CrossLayerCommunication.FluentValidation;

namespace UnitTest.FluentValidation
{
    [TestClass]
    public class TestIsBetween
    {
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestNullable()
        {
            //arrange
            int? valueToTest = 10;
            int greaterByOne = valueToTest.Value + 1,
                greaterByThree = valueToTest.Value + 3,
                lessByOne = valueToTest.Value - 1,
                lessByThree = valueToTest.Value - 3;

            //act, assert
            Assert.IsFalse(valueToTest.TestingFluentValidation().IsBetween(greaterByOne, greaterByThree).ValidationWasSuccessful);
            Assert.IsFalse(valueToTest.TestingFluentValidation().IsBetween(lessByThree, lessByOne).ValidationWasSuccessful);
            Assert.IsTrue(valueToTest.TestingFluentValidation().IsBetween(lessByThree, valueToTest.Value).ValidationWasSuccessful);
            Assert.IsTrue(valueToTest.TestingFluentValidation().IsBetween(valueToTest.Value, greaterByThree).ValidationWasSuccessful);
            Assert.IsTrue(valueToTest.TestingFluentValidation().IsBetween(lessByThree, greaterByThree).ValidationWasSuccessful);
            valueToTest.TestingFluentValidation().IsBetween(greaterByThree, lessByThree);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestNotNullable()
        {
            //arrange
            DateTime valueToTest = new DateTime(2011, 01, 01),
                     greaterByOne = valueToTest.AddDays(1),
                     greaterByThree = valueToTest.AddDays(3),
                     lessByOne = valueToTest.AddDays(-1),
                     lessByThree = valueToTest.AddDays(-3);

            //act, assert
            Assert.IsFalse(valueToTest.TestingFluentValidation().IsBetween(greaterByOne, greaterByThree).ValidationWasSuccessful);
            Assert.IsFalse(valueToTest.TestingFluentValidation().IsBetween(lessByThree, lessByOne).ValidationWasSuccessful);
            Assert.IsTrue(valueToTest.TestingFluentValidation().IsBetween(lessByThree, valueToTest).ValidationWasSuccessful);
            Assert.IsTrue(valueToTest.TestingFluentValidation().IsBetween(valueToTest, greaterByThree).ValidationWasSuccessful);
            Assert.IsTrue(valueToTest.TestingFluentValidation().IsBetween(lessByThree, greaterByThree).ValidationWasSuccessful);
            valueToTest.TestingFluentValidation().IsBetween(greaterByThree, lessByThree);
        }
    }
}
